package com.loto.webapp.action.manage;

import java.util.ArrayList;
import java.util.List;

import com.loto.webapp.common.BaseAction;
import com.loto.webapp.common.PageResultSet;
import com.loto.webapp.dao.UserDao;
import com.loto.webapp.model.User;

public class UserListAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -537789203062504909L;

	private UserDao userDao;
	private PageResultSet<Object> result;
	private List<User> userList;
	private int page = 1;
	private String pagerUrl;
	private String username;
	private int PAGE_SIZE = 15;
	private String btnQuery;

	public String execute() {
		if (btnQuery != null)
			page = 1;
		pagerUrl = "userList.do?page={0}";
		if (username != null && username != "") {
			pagerUrl = "userList.do?username=" + username + "&page={0}";
			result = userDao.getUserListByUsername(username, PAGE_SIZE, page);
		} else {
			pagerUrl = "userList.do?page={0}";
			result = userDao.getUserList(PAGE_SIZE, page);
		}
		setUserList((ArrayList) result.getList());

		return SUCCESS;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public PageResultSet<Object> getResult() {
		return result;
	}

	public void setResult(PageResultSet<Object> result) {
		this.result = result;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getPagerUrl() {
		return pagerUrl;
	}

	public void setPagerUrl(String pagerUrl) {
		this.pagerUrl = pagerUrl;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getBtnQuery() {
		return btnQuery;
	}

	public void setBtnQuery(String btnQuery) {
		this.btnQuery = btnQuery;
	}

	public int getPAGE_SIZE() {
		return PAGE_SIZE;
	}
}
